package com.tiancheng.trade.payment.channel.umsshop;

import com.tiancheng.trade.commom.core.utils.JsonUtil;
import com.tiancheng.trade.commom.core.utils.DateTimeUtil;
import com.tiancheng.trade.payment.channel.umsshop.request.UmsShopProcessWithdrawReq;
import com.tiancheng.trade.payment.channel.umsshop.request.UmsShopWithdrawMerchantBalanceQueryReq;
import com.tiancheng.trade.payment.channel.umsshop.request.UmsShopWithdrawStatusQueryReq;
import com.tiancheng.trade.payment.channel.umsshop.response.UmsShopProcessWithdrawRes;
import com.tiancheng.trade.payment.channel.umsshop.response.UmsShopWithdrawMerchantBalanceQueryRes;
import com.tiancheng.trade.payment.channel.umsshop.response.UmsShopWithdrawStatusQueryRes;
import com.tiancheng.trade.payment.channel.umsshop.util.UmsShopHttpUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 银联新购物车结算工具类
 */
@Component
public class UmsShopSettleClient {

    @Resource
    private UmsShopAllConfig umsShopAllConfig;

    public UmsShopWithdrawMerchantBalanceQueryRes queryWithdrawBalance(UmsShopProperties umsMopProperties,String mchntNo){
        UmsShopWithdrawMerchantBalanceQueryReq balanceQueryReq = new UmsShopWithdrawMerchantBalanceQueryReq();
        balanceQueryReq.setReqTs(DateTimeUtil.getCurrentDateTime());
        balanceQueryReq.setAppType("74");
        balanceQueryReq.setMchntNo(mchntNo);
        balanceQueryReq.setSysId("YN015");
        try {
            return new UmsShopHttpUtils<UmsShopWithdrawMerchantBalanceQueryRes>(umsMopProperties,
                    "v1/tn/cooperator/query-withdraw-balance").doPostToken(JsonUtil.toJsonString(balanceQueryReq), UmsShopWithdrawMerchantBalanceQueryRes.class);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 提现请求
     * @param umsShopProperties
     * @param params
     * @return
     */
    public UmsShopProcessWithdrawRes processWithdraw(UmsShopProperties umsShopProperties,UmsShopProcessWithdrawReq params){
        try {
            params.setAppType("74");
            params.setSysId("YN015");
            params.setNotifyUrl(umsShopProperties.getPayCallback());
            params.setReqTs(DateTimeUtil.getCurrentDateTime());
            return new UmsShopHttpUtils<UmsShopProcessWithdrawRes>(umsShopProperties,
                    "v1/tn/cooperator/process-withdraw").doPostToken(JsonUtil.toJsonString(params), UmsShopProcessWithdrawRes.class);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    };

    public UmsShopWithdrawStatusQueryRes queryWithdrawStatus(UmsShopProperties umsMopProperties, UmsShopWithdrawStatusQueryReq params){
        params.setReqTs(DateTimeUtil.getCurrentDateTime());
        params.setSysId("YN015");
        try {
            return new UmsShopHttpUtils<UmsShopWithdrawStatusQueryRes>(umsMopProperties,
                    "v1/tn/cooperator/query-order-status").doPostToken(JsonUtil.toJsonString(params), UmsShopWithdrawStatusQueryRes.class);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
